#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>

void random_init()
{
    int fd, ticks, i, r;
    struct timeval tv;

    gettimeofday(&tv, NULL);
    ticks = tv.tv_sec + tv.tv_usec;

    fd = open("/dev/urandom", O_RDONLY);
    if (fd > 0) {
        for (i = 0; i < 512; i++) {
            read(fd, &r, sizeof r);
            ticks += r;
        }
        close(fd);
    } 

    srand(ticks);
    //srandom(ticks);
}

int main(int argc, char *argv[])
{
    int i;

    random_init();
    
    for (i = 0; i < 10; i++) {
        printf("%d \n", rand());
        //printf("%ld \n", random());
    }

    return 0;
}
